<?php

/**
* Class cmsEditType: Super class for all EditTypes
*
* Each EditTypeClass must inherit this class and override the methods render_html(), render_javascript() and registerFields. This is
* necessary to unify the interface of each EditType used in a Plugin. So, it is easy to add a new EditType to extend an
* EditPlugin or to code own ones to provide new Types of cmsElements which can be used in a cmsDoc.
*/
class cmsEditType {

/**
* Constructor: sets the name of the EditType
*
* Builds a cmsEditType object with the given name and starts the registration of field names.
*
* @param object   $sender Reference to the cmsEditPlugin instance, which called the cmsEditType
* @param string   $name   Prefix used to build the name
* @param string   $descr  Description displayed in the form
*/
  function cmsEditType (&$sender,$name,$descr)
  {
    $this->sender = &$sender;
    $this->name   = $name;
    $this->descr  = $descr;
    $this->registerFields();
  }

/**
* Registers the fields
*
* The field names are needed by the cmsEditor to build the $data array which is used to tell the generic update method which
* updates the data of an cmsElement which fields of the data base table should be updated with which new data.
*
*
* override
*/
  function registerFields (){
     $map[] = $this->name.'_field';
     $this->map = &$map;
  }

/**
* Generates a string which shows the fields
*
* Shows the field names which are necessary to display contents in a template.
* e.g. #data[fieldName]#
*/
  function showFields (){
     return ''; //'<span style="color:#000080;font-size:10px">'.join("<br>\n",$this->map).'</span>';
  }

/**
* Returns the field map
*
* Returns the field map which is needed by the plugin and the editor.
*/
  function getMap (){
    return join(';',$this->map);
  }

/**
* Registers the owner of this EditType
*
* Stores a reference to the plugin object which contains this EditType object.
*
* @param cmsEditPlugin  $owner   Reference to the plugin object
*/
  function registerOwner (&$owner) {
    $this->owner = &$owner;
  }

/**
* encapsulates the getValue method for $this->owner
*
* provides a kind of short cut for the getValue method
*
* @param string  $field   field name form which the data should be returned
*/
  function getValue ($field) {
    return $this->owner->getValue($field);
  }

/**
* encapsulates the getValue method for $this->owner
*
* provides a kind of short cut for the getValue method
*
* @param string  $field   field name form which the data should be returned
*/
  function getLangValue ($field) {
    return $this->owner->getLangValue($field);
  }

/**
* Renders the EditType's form part
*
* override
*/
  function render_html () {
     $html .= '<input name="'.$this->name.'_field" value="'.$this->owner->getValue($this->name.'_field').'">';
     return $html;
  }

/**
* Renders the EditType's javascript part
*
* override
*/
  function render_javascript () {
     return "var test = 'hallo';\n";
  }

}
 ?>